package com.letv.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.letv.work.cp_info.CpInfoWorker;
import com.letv.work.leso.ListenLesoJob;

/**
 * CP business offline task Servlet class
 */
public class CpInfoServlet extends HttpServlet {

    /**
     * long
     */
    private static final long serialVersionUID = 1L;

    /**
     * Logger
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(CpInfoServlet.class);

    /**
     * doget
     * @param httpServletRequest HttpServletRequest
     * @param httpServletResponse HttpServletResponse
     */
    @Override
    public void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
        LOGGER.info("Receive the http call for CpInfo offline task...");
        if(ListenLesoJob.lesoJobIfRun()) {
            LOGGER.info("leso offlinetask is running now,don't run cpInfo offline task...");
            return;
        } else {
            LOGGER.info("leso offlinetask is finished now,can run cpInfo offline task...");
        }
        try {
            new Thread(new CpInfoWorker()).start();
        } catch(Exception e) {
            LOGGER.error("fail to call CpInfoServlet", e);
        }
    }

    /**
     * doPost
     * @param httpServletRequest HttpServletRequest
     * @param httpServletResponse HttpServletResponse
     */
    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
